<?php

namespace App\Http\Controllers\TeacherApi\User;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class RegisterController extends Controller
{
    use RegistersUsers;
    protected $redirectTo = '/'; //成功后跳转

    // public function __construct()
    // {
    //     $this->middleware('guest');
    // }

    //自定义获取视图地址
    public function showRegistrationForm()
    {
        return view('teacher.user.register');
    }

    //数据验证 
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'username' => 'required|string|max:12',
            //'nick' => 'required|string|max:12',
            'email' => 'required|string|email|max:30|unique:users',
            'password' => 'required|string|min:5|confirmed',
        ]);
    }

    //开始插入数据
    protected function create(array $data)
    {
        return Users::create([
            'username' => $data['username'],
            //'nick' => $data['nick'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
}
